# -*- coding: utf-8 -*-
# from lxml import etree as ET
import re
import datetime
from openpyxl import load_workbook
import os
import getpath
import logging
import re
def mylistdir(p,f):
    a=os.listdir(p)
    fs=myfind(a,f)
    return(fs)
def myfind(l,p):
    lr=[];
    #print p
    p1=p.replace(".",r"\.")
    p2=p1.replace("*",".*")
    p2=p2+"$"
    p2="^"+p2
    for a in l:
        #print a
        if  re.search(p2,a,re.IGNORECASE)==None :
           pass
           #print "pass"
        else:
           lr.append(a)
       #print "append"
    return lr

def yearbeforeday(d):
    try:
        d1 = datetime.datetime(d.year + 1, d.month, d.day)
        d1 = d1 + datetime.timedelta(-1)
    except ValueError as e:
        d1 = datetime.datetime(d.year + 1, d.month, d.day - 1)
        d1 = d1 + datetime.timedelta(-1)
    return d1


def set_cell(table, row, col, value):
    print(row, col, value)
    table.cell(row=row, column=col, value=value)


def get_cell(table, row, col):
    return table.cell(row=row, column=col).value


def gen_jiao_zhun(fn):
    xl_book = load_workbook(filename=fn)
    ffbh = getSheet(xl_book,0)
    return (ffbh)


def getSheet(xlBook, at):
    ffbh = []
    table = xlBook.worksheets[at]
    rows = table.rows
    for row in rows:
        cell = row[0]
        ffbh.append(cell.value)
    return ffbh
def getData():
    path=r'\\10.0.114.230\化学分析室\仪器采集\caiji\leco_on_back'
    fs=mylistdir(path,"*.xlsx")
    r=[]
    for f in fs:
        print(f)
        data = gen_jiao_zhun(os.path.join(path,f))
        if data[-2] in r:
            pass
        else:
            r.append(data[-2])
    return r
if __name__ == "__main__":
    print(getData())
